package com.ebt.m.proposal_v2.helper;

import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.StateListDrawable;
import android.os.Build;

/**
 * @author archer.qi
 *         Created on 2017/5/4.
 */
public class ViewHelper {
    private static final String TAG = ViewHelper.class.getSimpleName();

    /* Selector状态*/
    public static final int SELECTOR_STATE_PRESSED = android.R.attr.state_pressed;
    public static final int SELECTOR_STATE_FOCUSED = android.R.attr.state_focused;
    public static final int SELECTOR_STATE_CHECKED = android.R.attr.state_checked;

    /**
     * 生成一个Selector
     *
     * @param states
     * @param normal
     * @param stated
     * @return
     */
    public static StateListDrawable generateSelector(int[] states, Drawable normal, Drawable stated) {
        StateListDrawable stateList = new StateListDrawable();
        stateList.addState(states, stated);
        stateList.addState(new int[]{}, normal);

        if (Build.VERSION.SDK_INT > 10) {
            stateList.setEnterFadeDuration(350);
            stateList.setExitFadeDuration(350);
        }
        return stateList;
    }

    /**
     * 生成一个Press效果的Selector
     *
     * @param normal
     * @param stated
     * @return
     */
    public static StateListDrawable generatePressSelector(Drawable normal, Drawable stated) {
        return generateSelector(new int[]{SELECTOR_STATE_PRESSED, SELECTOR_STATE_FOCUSED}, normal, stated);
    }

    /**
     * 生成一个Check效果的Selector
     *
     * @param normal
     * @param stated
     * @return
     */
    public static StateListDrawable generateCheckSelector(Drawable normal, Drawable stated) {
        return generateSelector(new int[]{SELECTOR_STATE_CHECKED}, normal, stated);
    }

    /**
     * Shape定义的Drawable
     * <p>
     * 一个空的GradientDrawable，可以随意定制
     * </p>
     *
     * @return
     */
    public static GradientDrawable generateGradientDrawable() {
        return new GradientDrawable();
    }

    /**
     * 生成一个圆角填充色的Drawable
     *
     * @param cornerRadius
     * @param solidColor
     * @return
     */
    public static GradientDrawable genetateCornerGradientDrawable(float cornerRadius, int solidColor) {
        GradientDrawable shape = new GradientDrawable();
        shape.setShape(GradientDrawable.RECTANGLE);
        shape.setCornerRadius(cornerRadius);
        shape.setColor(solidColor);
        return shape;
    }

    /**
     * 生成一个圆角白色背景带有色边框的Drawable
     *
     * @param cornerRadius
     * @param strokeColor
     * @return
     */
    public static GradientDrawable genetateCornerStrokedGradientDrawable(float cornerRadius, int solidColor, int strokeColor) {
        GradientDrawable shape = new GradientDrawable();
        shape.setShape(GradientDrawable.RECTANGLE);
        shape.setCornerRadius(cornerRadius);
        shape.setColor(solidColor);
        shape.setStroke(2, strokeColor);
        return shape;
    }


}
